{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Automatic python script for compilation of f2py-wrapped EVPSC Fortran code\n",
      "for an interactive python environment.\n",
      "\n",
      "Arguments for the fixed gfortran compiler are:\n",
      "-finit-local-zero\n",
      "-fno-automatic\n",
      "-g\n",
      "-Wall\n",
      "-fno-align-commons\n",
      "-finit-integer=zero\n",
      "-fbackslash\n",
      "-finit-real=zero\n",
      "-fdefault-double-8\n",
      "-fdefault-real-8\n",
      "f2py -c --f90exec='/usr/local/bin/gfortran' --f77exec='/usr/local/bin/gfortran' --f77flags='-finit-local-zero -fno-automatic -g -Wall -fno-align-commons -finit-integer=zero -fbackslash -finit-real=zero -fdefault-double-8 -fdefault-real-8 -O3' --f90flags='-finit-local-zero -fno-automatic -g -Wall -fno-align-commons -finit-integer=zero -fbackslash -finit-real=zero -fdefault-double-8 -fdefault-real-8 -O3' -m cs cs.f > f2py_cmp_temp\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import compile; compile.main(filename='cs.f', outbin='cs',optimization=3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Populating the interactive namespace from numpy and matplotlib\n"
     ]
    }
   ],
   "source": [
    "%pylab inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 1.  0.  0.]\n",
      " [ 0.  1.  0.]\n",
      " [ 0.  0.  1.]]\n"
     ]
    }
   ],
   "source": [
    "idx = np.zeros((3,3))\n",
    "idx[0,0] = 1.\n",
    "idx[1,1] = 1.\n",
    "idx[2,2] = 1.\n",
    "print idx"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "ImportError",
     "evalue": "dlopen(./cs.so, 2): Symbol not found: _add33mat_\n  Referenced from: ./cs.so\n  Expected in: dynamic lookup\n",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m                               Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-6-fced5418ff98>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0mcs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mImportError\u001b[0m: dlopen(./cs.so, 2): Symbol not found: _add33mat_\n  Referenced from: ./cs.so\n  Expected in: dynamic lookup\n"
     ]
    }
   ],
   "source": [
    "import cs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.66666667 -0.33333333  0.66666667]\n",
      " [ 0.66666667  0.66666667 -0.33333333]\n",
      " [-0.33333333  0.66666667  0.66666667]]"
     ]
    }
   ],
   "source": [
    "rot=cs.vector_ang(u=[1,1,1], th=60.)\n",
    "print rot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "rot=cs.vector_ang(u=[1,1,1], th=60.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ -1.00000000e+00,   1.22460635e-16,   0.00000000e+00],\n",
       "       [  1.22460635e-16,   1.00000000e+00,   0.00000000e+00],\n",
       "       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cs.reflect(th=90.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  2.22044605e-16,   1.00000000e+00,   0.00000000e+00],\n",
       "       [  1.00000000e+00,  -2.22044605e-16,   0.00000000e+00],\n",
       "       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cs.mirror110()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[  6.12303177e-17,  -1.00000000e+00,   0.00000000e+00],\n",
       "       [  1.00000000e+00,   6.12303177e-17,   0.00000000e+00],\n",
       "       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]]),\n",
       " array([[ -1.00000000e+00,  -1.22460635e-16,   0.00000000e+00],\n",
       "       [  1.22460635e-16,  -1.00000000e+00,   0.00000000e+00],\n",
       "       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]]),\n",
       " array([[ -1.83690953e-16,   1.00000000e+00,   0.00000000e+00],\n",
       "       [ -1.00000000e+00,  -1.83690953e-16,   0.00000000e+00],\n",
       "       [  0.00000000e+00,   0.00000000e+00,   1.00000000e+00]]))"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cs.rot100_90_180_270()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cubic_rot_sym - Function signature:\n",
      "  h,n = cubic_rot_sym(icen)\n",
      "Required arguments:\n",
      "  icen : input int\n",
      "Return objects:\n",
      "  h : rank-3 array(&apos;d&apos;) with bounds (3,3,48)\n",
      "  n : int\n"
     ]
    }
   ],
   "source": [
    "print cs.cubic_rot_sym.__doc__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "h,n=cs.cubic_rot_sym(icen=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "48"
     ]
    }
   ],
   "source": [
    "print n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "hh=h.swapaxes(0,2).swapaxes(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 1 \n",
      " 1  0  0\n",
      " 0  1  0\n",
      " 0  0  1\n",
      "\n",
      " 2 \n",
      " 0  0  1\n",
      " 1  0  0\n",
      " 0  1  0\n",
      "\n",
      " 3 \n",
      " 0  1  0\n",
      " 0  0  1\n",
      " 1  0  0\n",
      "\n",
      " 4 \n",
      " 0  1  0\n",
      " 1  0  0\n",
      " 0  0  1\n",
      "\n",
      " 5 \n",
      " 0  0  1\n",
      " 0  1  0\n",
      " 1  0  0\n",
      "\n",
      " 6 \n",
      " 1  0  0\n",
      " 0  0  1\n",
      " 0  1  0\n",
      "\n",
      " 7 \n",
      " 0 -1  0\n",
      " 1  0  0\n",
      " 0  0  1\n",
      "\n",
      " 8 \n",
      "-1  0  0\n",
      " 0 -1  0\n",
      " 0  0  1\n",
      "\n",
      " 9 \n",
      " 0  1  0\n",
      "-1  0  0\n",
      " 0  0  1\n",
      "\n",
      "10 \n",
      " 0  0  1\n",
      " 0 -1  0\n",
      " 1  0  0\n",
      "\n",
      "11 \n",
      " 0  0  1\n",
      "-1  0  0\n",
      " 0 -1  0\n",
      "\n",
      "12 \n",
      " 0  0  1\n",
      " 0  1  0\n",
      "-1  0  0\n",
      "\n",
      "13 \n",
      " 1  0  0\n",
      " 0  0  1\n",
      " 0 -1  0\n",
      "\n",
      "14 \n",
      " 0 -1  0\n",
      " 0  0  1\n",
      "-1  0  0\n",
      "\n",
      "15 \n",
      "-1  0  0\n",
      " 0  0  1\n",
      " 0  1  0\n",
      "\n",
      "16 \n",
      " 1  0  0\n",
      " 0 -1  0\n",
      " 0  0  1\n",
      "\n",
      "17 \n",
      " 0 -1  0\n",
      "-1  0  0\n",
      " 0  0  1\n",
      "\n",
      "18 \n",
      "-1  0  0\n",
      " 0  1  0\n",
      " 0  0  1\n",
      "\n",
      "19 \n",
      " 0  0  1\n",
      " 1  0  0\n",
      " 0 -1  0\n",
      "\n",
      "20 \n",
      " 0  0  1\n",
      " 0 -1  0\n",
      "-1  0  0\n",
      "\n",
      "21 \n",
      " 0  0  1\n",
      "-1  0  0\n",
      " 0  1  0\n",
      "\n",
      "22 \n",
      " 0 -1  0\n",
      " 0  0  1\n",
      " 1  0  0\n",
      "\n",
      "23 \n",
      "-1  0  0\n",
      " 0  0  1\n",
      " 0 -1  0\n",
      "\n",
      "24 \n",
      " 0  1  0\n",
      " 0  0  1\n",
      "-1  0  0\n",
      "\n",
      "25 \n",
      "-1  0  0\n",
      " 0 -1  0\n",
      " 0  0 -1\n",
      "\n",
      "26 \n",
      " 0  0 -1\n",
      "-1  0  0\n",
      " 0 -1  0\n",
      "\n",
      "27 \n",
      " 0 -1  0\n",
      " 0  0 -1\n",
      "-1  0  0\n",
      "\n",
      "28 \n",
      " 0 -1  0\n",
      "-1  0  0\n",
      " 0  0 -1\n",
      "\n",
      "29 \n",
      " 0  0 -1\n",
      " 0 -1  0\n",
      "-1  0  0\n",
      "\n",
      "30 \n",
      "-1  0  0\n",
      " 0  0 -1\n",
      " 0 -1  0\n",
      "\n",
      "31 \n",
      " 0  1  0\n",
      "-1  0  0\n",
      " 0  0 -1\n",
      "\n",
      "32 \n",
      " 1  0  0\n",
      " 0  1  0\n",
      " 0  0 -1\n",
      "\n",
      "33 \n",
      " 0 -1  0\n",
      " 1  0  0\n",
      " 0  0 -1\n",
      "\n",
      "34 \n",
      " 0  0 -1\n",
      " 0  1  0\n",
      "-1  0  0\n",
      "\n",
      "35 \n",
      " 0  0 -1\n",
      " 1  0  0\n",
      " 0  1  0\n",
      "\n",
      "36 \n",
      " 0  0 -1\n",
      " 0 -1  0\n",
      " 1  0  0\n",
      "\n",
      "37 \n",
      "-1  0  0\n",
      " 0  0 -1\n",
      " 0  1  0\n",
      "\n",
      "38 \n",
      " 0  1  0\n",
      " 0  0 -1\n",
      " 1  0  0\n",
      "\n",
      "39 \n",
      " 1  0  0\n",
      " 0  0 -1\n",
      " 0 -1  0\n",
      "\n",
      "40 \n",
      "-1  0  0\n",
      " 0  1  0\n",
      " 0  0 -1\n",
      "\n",
      "41 \n",
      " 0  1  0\n",
      " 1  0  0\n",
      " 0  0 -1\n",
      "\n",
      "42 \n",
      " 1  0  0\n",
      " 0 -1  0\n",
      " 0  0 -1\n",
      "\n",
      "43 \n",
      " 0  0 -1\n",
      "-1  0  0\n",
      " 0  1  0\n",
      "\n",
      "44 \n",
      " 0  0 -1\n",
      " 0  1  0\n",
      " 1  0  0\n",
      "\n",
      "45 \n",
      " 0  0 -1\n",
      " 1  0  0\n",
      " 0 -1  0\n",
      "\n",
      "46 \n",
      " 0  1  0\n",
      " 0  0 -1\n",
      "-1  0  0\n",
      "\n",
      "47 \n",
      " 1  0  0\n",
      " 0  0 -1\n",
      " 0  1  0\n",
      "\n",
      "48 \n",
      " 0 -1  0\n",
      " 0  0 -1\n",
      " 1  0  0\n"
     ]
    }
   ],
   "source": [
    "for i in range(n): \n",
    "    print \"%2i \\n%2i %2i %2i\\n%2i %2i %2i\\n%2i %2i %2i\\n\"%\\\n",
    "    (i+1,\n",
    "     h[0,0,i], \n",
    "     h[0,1,i], \n",
    "     h[0,2,i], \n",
    "     h[1,0,i], \n",
    "     h[1,1,i], \n",
    "     h[1,2,i],\n",
    "     h[2,0,i], \n",
    "     h[2,1,i], \n",
    "     h[2,2,i]\n",
    "     )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "ename": "IOError",
     "evalue": "This follow uniqpnset is buggy for ipython notebook environment.",
     "output_type": "error",
     "traceback": [
      "<span class=\"ansired\">---------------------------------------------------------------------------</span>\n<span class=\"ansired\">IOError</span>                                   Traceback (most recent call last)",
      "<span class=\"ansigreen\">/Users/yj/Dropbox/devel/test/fortran/&lt;ipython-input-14-a7515354a95b&gt;</span> in <span class=\"ansicyan\">&lt;module&gt;</span><span class=\"ansiblue\">()</span>\n<span class=\"ansigreen\">      3</span> <span class=\"ansired\"># false array dimension declaration.</span>\n<span class=\"ansiblue\"></span>\n<span class=\"ansigreen\">      4</span> <span class=\"ansired\"># But still, the pure fortran executable seems working fine.</span>\n<span class=\"ansiblue\"></span>\n<span class=\"ansigreen\">----&gt; 5</span><span class=\"ansired\"> </span><span class=\"ansigreen\">raise</span> IOError<span class=\"ansiblue\">,</span> <span class=\"ansiblue\">&apos;This follow uniqpnset is buggy for ipython notebook environment.&apos;</span><span class=\"ansiblue\"></span>\n<span class=\"ansigreen\">      6</span> n<span class=\"ansiblue\">=</span><span class=\"ansiblue\">[</span><span class=\"ansicyan\">1</span><span class=\"ansiblue\">,</span><span class=\"ansicyan\">0</span><span class=\"ansiblue\">,</span><span class=\"ansicyan\">1</span><span class=\"ansiblue\">]</span><span class=\"ansiblue\">;</span> b<span class=\"ansiblue\">=</span><span class=\"ansiblue\">[</span><span class=\"ansicyan\">1</span><span class=\"ansiblue\">,</span><span class=\"ansicyan\">1</span><span class=\"ansiblue\">,</span><span class=\"ansicyan\">1</span><span class=\"ansiblue\">]</span><span class=\"ansiblue\"></span>\n<span class=\"ansigreen\">      7</span> ipr <span class=\"ansiblue\">=</span> True<span class=\"ansiblue\"></span>\n",
      "<span class=\"ansired\">IOError</span>: This follow uniqpnset is buggy for ipython notebook environment."
     ]
    }
   ],
   "source": [
    "# subroutine uniqpnset is not working rightly\n",
    "# It seems that it has something to do with the\n",
    "# false array dimension declaration.\n",
    "# But still, the pure fortran executable seems working fine.\n",
    "raise IOError, 'This follow uniqpnset is buggy for ipython notebook environment.'\n",
    "n=[1,0,1]; b=[1,1,1]\n",
    "ipr = True\n",
    "uni, n = cs.uniqpnset(n=n,b=b,isym=1,ipr=ipr)\n",
    "print n\n",
    "type(uni)\n",
    "print uni.shape\n",
    "u = uni.swapaxes(0,2)\n",
    "\n",
    "for i in range(n): \n",
    "    print \"%2i %2i %2i    %2i %2i %2i\\n\"%\\\n",
    "    (u[i,0,0], u[i,0,1], u[i,0,2], u[i,1,0], u[i,1,1], u[i,1,2])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0.00894391, -0.89439142,  0.44719571])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cs.unitcv(miller=[2,-200,100], icrysym=1, angs=[90,90,90], cdim=[1,1,1], verbose=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
